/*
 * Copyright (c) 1994-2017, Joyoung Stock CO.LTD.
 * The FWJR Project.
 * All Rights Reserved.
 */

package com.qdsg.ysg.doctor.ui.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import androidx.annotation.NonNull;
import com.qdsg.ysg.doctor.R;
import com.qdsg.ysg.doctor.base.BaseDialogFragment;


public class CheckDialog extends BaseDialogFragment implements View.OnClickListener {
    private OnItemClickListener mListener;
    private Dialog mDialog;

    public static CheckDialog newInstance() {
        return new CheckDialog();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    @NonNull
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        mDialog = super.onCreateDialog(savedInstanceState);
        mDialog.setCancelable(false);
        Window window = mDialog.getWindow();
        if (window != null) {
            window.setGravity(Gravity.BOTTOM);
        }
        return mDialog;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View mView = inflater.inflate(R.layout.dialog_check, container, false);
        mView.setMinimumWidth(mScreenWidth);
        mView.findViewById(R.id.tv_check).setOnClickListener(this);
        mView.findViewById(R.id.tv_refuse).setOnClickListener(this);
        mView.findViewById(R.id.txt_cancel).setOnClickListener(this);
        return mView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getDialog().setCanceledOnTouchOutside(false);
    }

    public interface OnItemClickListener {
        void check();

        void refuse();
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_check: {
                mListener.check();
                dismiss();
            }
            break;
            case R.id.tv_refuse: {
                mListener.refuse();
                dismiss();
            }
            break;
            case R.id.txt_cancel: {
                dismiss();
            }
            break;
            default:
                break;
        }
    }

    public boolean isShowing() {
        return mDialog != null && mDialog.isShowing();
    }
}
